package util

import "sync"

// WaitGroup wraps util WaitGroup, like errgroup
type WaitGroup struct {
	wg sync.WaitGroup
}

// NewWaitGroup new waitgroup
func NewWaitGroup() *WaitGroup {
	return &WaitGroup{}
}

// Go add func to group
func (g *WaitGroup) Go(fn func()) {
	go func() {
		g.wg.Add(1)
		fn()
		g.wg.Done()
	}()
}

// Wait waits all goroutine finished
func (g *WaitGroup) Wait() {
	g.wg.Wait()
}
